package com.faner.controller;

import com.faner.source.SpringSourceCode;
import com.fun.frame.SourceCode;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
public class MyController extends SourceCode {

    private static org.slf4j.Logger logger = LoggerFactory.getLogger(MyController.class);

    @Autowired
    private HttpServletRequest request;

    @RequestMapping(value = "/", method = RequestMethod.GET)
    @ResponseBody
    void home(HttpServletResponse response) throws IOException {
        logger.info("首页，header:{}", SpringSourceCode.getIpAddr(request));
        response.sendRedirect("/blog/home.html");
    }

    @RequestMapping("/mobile")
    String mobile() {
        return "index";
    }

    @RequestMapping("/find")
    String find(@RequestParam("loginName") String loginName, @RequestParam("password") String password) {
        if (loginName.equals("fan") && password.equals("111111"))
            return "my";
        return "404";
    }

//    @RequestMapping("/cpu")
//    String get() {
//        List<Integer> list = new ArrayList<>();
//        for (int i = 0; i < 10000; i++) {
//            list.add(i);
//        }
//        get(list, 0);
//        StringBuffer a = new StringBuffer();
//        list.forEach(n -> a.append(a));
//        return a.toString();
//    }
//
//    @RequestMapping("/mem")
//    long get22() {
//        List<String> list = new ArrayList<>();
//        for (int i = 0; i < 10000; i++) {
//            list.add(i + RString.getString(100));
//        }
//        StringBuffer a = new StringBuffer();
//        list.forEach(n -> a.append(a));
//        return a.toString().length();
//    }
//
//    static void get(List<Integer> list, int tt) {
//        int num = list.get(tt);
//        for (int i = tt + 1; i < list.size(); i++) {
//            if (list.get(i) % num == 0) list.remove(i--);
//        }
//        if (list.size() > ++tt) get(list, tt);
//    }
}
